package fr.afcepf.atod19.dreamproject.dao.implementation;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import fr.afcepf.atod19.dreamproject.dao.interfaces.TestIDaoCommande;
import fr.afcepf.atod19.dreamproject.entity.Commande;
import fr.afcepf.atod19.dreamproject.entity.LigneCommande;

public class TestDaoCommande implements TestIDaoCommande {
	
	@PersistenceContext
	private EntityManager em;
	
	@Override
	public int createCommande(Commande cmd) {
		System.out.println("createCommande cmd");
		em.persist(cmd);
		System.out.println("passe dans le dao");
		int b = cmd.getIdCommande();
		
		for (LigneCommande lc : cmd.getLigneCommandes()) {
		
			em.persist(lc);

		}
		
		em.close();
		return b;
	}
	
	public EntityManager getEm() {
		return em;
	}

	public void setEm(EntityManager em) {
		this.em = em;
	}
}
